using System;

namespace OracleInternal.Json.Sql
{
	internal class OracleJsonFloat : OracleJsonNumber
	{
		private const string s_NAN = "\"Nan\"";

		private float m_value;

		internal OracleJsonFloat(float value)
		{
			m_value = value;
		}

		public override OracleJsonType GetOracleJsonType()
		{
			return OracleJsonType.FLOAT;
		}

		public override bool Equals(object other)
		{
			if (!(other is OracleJsonFloat))
			{
				return false;
			}
			OracleJsonFloat oracleJsonFloat = (OracleJsonFloat)other;
			return BitConverter.GetBytes(m_value) == BitConverter.GetBytes(oracleJsonFloat.FloatValue());
		}

		public override int GetHashCode()
		{
			return m_value.GetHashCode();
		}

		internal override decimal BigDecimalValue()
		{
			return (decimal)m_value;
		}

		internal override float FloatValue()
		{
			return m_value;
		}

		internal override string GetJsonString()
		{
			if (float.IsPositiveInfinity(m_value))
			{
				return OracleJsonDecimal.POSITIVE_INF;
			}
			if (float.IsNegativeInfinity(m_value))
			{
				return OracleJsonDecimal.NEGATIVE_INF;
			}
			if (float.IsNaN(m_value))
			{
				return "\"Nan\"";
			}
			return m_value.ToString();
		}
	}
}
